package cn.zhl.设计模式.命令;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2021-03-22 11:21
 **/
public class RemoteController {
	private Command[] onCommands = new Command[5];
	private Command[] offCommands = new Command[5];

	private Command undoButton = new NoCommand();

	public RemoteController(){
		for(int i = 0; i< 5 ;i++){
			onCommands[i] = new NoCommand();
			offCommands[i] = new NoCommand();
		}
	}

	public void setCommond(int index,Command onCommand,Command offCommand){
		onCommands[index] = onCommand;
		offCommands[index] = offCommand;
	}

	public void startButtonPushed(int index){
		onCommands[index].execute();
		undoButton = onCommands[index];
	}

	public void offButtonPushed(int index){
		offCommands[index].execute();
		undoButton = offCommands[index];
	}

	public void undoButtonPushed(){
		undoButton.undo();
	}
}
